package com.ruoyi.web.admin.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import  com.ruoyi.web.admin.domain.TdmCmc;
import  com.ruoyi.web.admin.service.ITdmCmcService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * CMCController
 * 
 * @author ruoyi
 * @date 2022-03-10
 */
@RestController
@RequestMapping("/admin/cmc")
public class TdmCmcController extends BaseController
{
    @Autowired
    private ITdmCmcService tdmCmcService;

    /**
     * 查询CMC列表
     */
//    @PreAuthorize("@ss.hasPermi('admin:cmc:list')")
    @GetMapping("/list")
    public TableDataInfo list(TdmCmc tdmCmc)
    {
        startPage();
        List<TdmCmc> list = tdmCmcService.selectTdmCmcList(tdmCmc);
        return getDataTable(list);
    }

    /**
     * 导出CMC列表
     */
//    @PreAuthorize("@ss.hasPermi('admin:cmc:export')")
    @Log(title = "CMC", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TdmCmc tdmCmc)
    {
        List<TdmCmc> list = tdmCmcService.selectTdmCmcList(tdmCmc);
        ExcelUtil<TdmCmc> util = new ExcelUtil<TdmCmc>(TdmCmc.class);
        util.exportExcel(response, list, "CMC数据");
    }

    /**
     * 获取CMC详细信息
     */
//    @PreAuthorize("@ss.hasPermi('admin:cmc:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(tdmCmcService.selectTdmCmcById(id));
    }

    /**
     * 新增CMC
     */
//    @PreAuthorize("@ss.hasPermi('admin:cmc:add')")
    @Log(title = "CMC", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TdmCmc tdmCmc)
    {
        return toAjax(tdmCmcService.insertTdmCmc(tdmCmc));
    }

    /**
     * 修改CMC
     */
//    @PreAuthorize("@ss.hasPermi('admin:cmc:edit')")
    @Log(title = "CMC", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TdmCmc tdmCmc)
    {
        return toAjax(tdmCmcService.updateTdmCmc(tdmCmc));
    }

    /**
     * 删除CMC
     */
//    @PreAuthorize("@ss.hasPermi('admin:cmc:remove')")
    @Log(title = "CMC", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tdmCmcService.deleteTdmCmcByIds(ids));
    }
}
